<#include "../../select.ftl" />
<#assign security=JspTaglibs["/WEB-INF/security.tld"] />
<!DOCTYPE html>
<html>
<head>
<title>维护页面</title>
<script type="text/javascript">
function popAddOrModify(id) {
    var data = {};
    var url = '${absoluteContextPath}/yk/ykOrder';
    if (id != undefined) {
        data.id = id;
        url = url + "/goEdit";
    } else {
        url = url + "/goAdd";
    }
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#myModal');
                pop_div.html(data.content.data);
                pop_div.modal('show');
            } else {
                $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}

function deleteYkOrder() {
    var i = 0;
    $("input[name=ids]").each(function () {
        if ($(this).prop("checked")) {
            i++;
        }
    });
    if (i == 0) {
        $.showMessage({parentId: "showMessage", message: "请选择您要删除的记录！", type: "success"});
        return false;
    } else {
        $.confirm({
            confirm: function () {
                var values = "";
                $("input[name=ids]").each(function () {
                    if ($(this).prop("checked")) {
                        values += $(this).val() + ",";
                    }
                });
                $("#confirmModal").modal("hide");
                $.post("${absoluteContextPath}/yk/ykOrder/delete", {
                    'ids': values
                }, function (data) {
                    data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        $.showMessage({parentId: "showMessage", message: "数据删除成功！", type: "success"});
                        refreshTable();
                    } else {
                        $.showMessage({parentId: "showMessage", message: "数据删除异常！", type: "error"});
                    }
                });
            }
        });
    }
}

function refreshTable() {
    $("input[name=currentPage]").val(1);
    $("#search_ykOrder_table").ajaxSubmit({
        url: '${absoluteContextPath}/yk/ykOrder/ajaxList',
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                $("#tableContent").html(data.content.data);
            } else {
                $.showMessage({parentId: "showMessage", message: "表格数据加载异常！", type: "success"});
            }
        }
    });
}


//选择卡名称
function dorefreshcardtype(target) {
    var data = {};
    var url = '${absoluteContextPath}/yk/ykType';
    url = url + "/dorefreshyktype";
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#myModal2');
                pop_div.html(data.content.data);
                pop_div.modal('show');
                $(pop_div).find("#confirm").click(function () {
                    var id = $("#selectVipId").val();
                    var name = $("#selectProductName").val();
                    $(target).parent().find("input[name=vipId]").val(id);
                    $(target).parent().find("input[name=productName]").val(name);
                    $('#myModal2').modal("hide");
                    funGoYkType(id);
                });
            } else {
                $.showMessage({parentId: "errorMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}


//选择分管人
function doSelctReferralsUser(target) {
    var usingOrgId = $("#orgId").val();
    var data = {};
    var url = '${absoluteContextPath}/system/user';
    url = url + "/goSelectSaleUser";
    data.usingOrgId = usingOrgId;
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#myModal2');
                pop_div.html(data.content.data);
                pop_div.modal('show');
                $(pop_div).find("#confirm").click(function () {
                    var id = $("#selectUserId").val();
                    var name = $("#selectUserName").val();
                    $(target).parent().find("input[name=fgId]").val(id);
                    $(target).parent().find("input[name=fgName]").val(name);
                    $('#myModal2').modal("hide");
                });
            } else {
                $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}


//选择促会人
function doSelctIllIndex(target) {
    var illIndexId = $(target).parent().find("input[name=chId]").val();
    var illIndexName = $(target).parent().find("input[name=chName]").val();
    var data = {};
    var url = '${absoluteContextPath}/system/user';
    url = url + "/goSelectIllIndex";
    data.selectType = "Multiselect";
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#myModal2');
                pop_div.html(data.content.data);
                pop_div.modal('show');
                $(pop_div).find("#confirm").click(function () {
                    var illIndexIds = "";
                    var illIndexNames = "";
                    $("#search_illIndexs_table input[name=ids]").each(function () {
                        if ($(this).prop("checked")) {
                            illIndexIds += $(this).parent().parent().children("td:eq(1)").text() + ",";
                            illIndexNames += $(this).parent().parent().children("td:eq(2)").text() + ",";
                        }
                    });
                    $(target).parent().find("input[name=chId]").val(illIndexIds);
                    $(target).parent().find("input[name=chName]").val(illIndexNames);
                    $('#myModal2').modal("hide");
                });
            } else {
                $.showMessage({parentId: "errorMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}


//选择引荐人
function doSelctHealthYj(target) {

    var illIndexId = $(target).parent().find("input[name=yjId]").val();
    var illIndexName = $(target).parent().find("input[name=yjName]").val();
    var data = {};
    var url = '${absoluteContextPath}/system/user';
    url = url + "/goSelectIllIndex";
    data.selectType = "Multiselect";
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.returnCode == 1) {
                var pop_div = $('#myModal2');
                pop_div.html(data.content.data);
                pop_div.modal('show');
                $(pop_div).find("#confirm").click(function () {
                    var illIndexIds = "";
                    var illIndexNames = "";
                    $("#search_illIndexs_table input[name=ids]").each(function () {
                        if ($(this).prop("checked")) {
                            illIndexIds += $(this).parent().parent().children("td:eq(1)").text() + ",";
                            illIndexNames += $(this).parent().parent().children("td:eq(2)").text() + ",";
                        }
                    });
                    //省略最后一个逗号
//                    if (illIndexIds.contains(",")) {
//                        illIndexIds = illIndexIds.substring(0, illIndexIds.lastIndexOf(","));
//                        illIndexNames = illIndexNames.substring(0, illIndexNames.lastIndexOf(","));
//                    }
                    $(target).parent().find("input[name=yjId]").val(illIndexIds);
                    $(target).parent().find("input[name=yjName]").val(illIndexNames);
                    $('#myModal2').modal("hide");
                });
            } else {
                $.showMessage({parentId: "errorMessage", message: "数据加载异常！", type: "success"});
            }
        }
    });
}
//        导入
$(function () {
    $("#importCustBtn").click(function () {
        $("#custUploadForm input[type=file]").click();
    });

    $("#custUploadForm input[name=file]").live("change", function () {
        $("#custUploadForm").ajaxSubmit({
            success: function (data) {
                importCustSuccess(data);
            }
        });
    });
});
function importCustSuccess(data) {
    var result = JSON.parse(data);
    if (result.returnCode == 1) {
        var url = "${absoluteContextPath}/yk/ykOrder/importOrder";
        var path = result.content;
        $.ajax({
            url: url,
            type: 'post',
            data: {path: path},
            success: function (msg) {
                refreshTable();
                msg = JSON.parse(msg);
                var pop_div = $('#errorMessage');
                var message = "";
                var texts = {};
                texts = msg.returnMsg.split("!");
                for (var r = 0; r < texts.length; r++) {
                    if (r < texts.length - 1) {
                        message += (texts[r] + "!<br>");
                    } else {
                        message += (texts[r]);
                    }
                }
                $("#info").html(message);
                pop_div.modal('show');
                $("input[name=file]").val(null);

            }
        });
    } else {
        $.showMessage({parentId: "showMessage", message: "<strong>错误信息</strong>：" + result.returnMsg, type: "error"});
    }
}
function doDownLoadTemplate() {
    $("#Form_Download").submit();
}
$(function () {
    $("input[name=billTime]").focus(function () {
        WdatePicker({dateFmt: 'yyyy-MM-dd'});

    })

    $("input[name=billFinish]").focus(function () {
        WdatePicker({dateFmt: 'yyyy-MM-dd'});

    })

    $("input[name=finishStart]").focus(function () {
        WdatePicker({dateFmt: 'yyyy-MM-dd'});

    })

    $("input[name=finishEnd]").focus(function () {
        WdatePicker({dateFmt: 'yyyy-MM-dd'});
    })
    $("input[name=billStart]").focus(function () {
        WdatePicker({dateFmt: 'yyyy-MM-dd'});
    })

    $("input[name=billEnd]").focus(function () {
        WdatePicker({dateFmt: 'yyyy-MM-dd'});
    })

    $("div[class='tooltip fade top in']").hide();
});
function popExportExcel() {
    $("#search_ykOrder_table").attr('action', '${absoluteContextPath}/yk/ykOrder/export');
    $("#search_ykOrder_table").submit();
    $("#search_ykOrder_table").attr('action', '${absoluteContextPath}/yk/ykOrder/list');
}
</script>
</head>
<body>

<div class="breadcrumbs">
    <ol class="breadcrumb">
        <li><a href="${absoluteContextPath}/home"><i class="fa fa-home"></i>首页</a></li>
        <li><a href="#">财务系统</a></li>
        <li class="active">会员管理</li>
    </ol>
</div>

<div class="main">
<!-- row -->
<div class="row">
<div class="col-md-12">
<section class="tile">
<!-- tile body -->
<div class="tile-body">
<div id="showMessage"><#include "../../message.ftl" /></div>
<div class="form-horizontal">
<form id="search_ykOrder_table" action="${absoluteContextPath}/yk/ykOrder/list" method="post">
<#--<input type="hidden" name="pageSize" value="${ykOrdersTable.page.pageSize}"/>-->
<input type="hidden" name="currentPage" value="${ykOrdersTable.page.currentPage}"/>


<div class="row">
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">订单编号</label>

        <div class="col-sm-8">
            <input class="form-control" name="billId" value="${ykOrderParams.billId!''}" placeholder="" type="text">
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">客户编号</label>

        <div class="col-sm-8">
            <input class="form-control" name="userId" value="${ykOrderParams.userId!''}" placeholder="" type="text">
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">客户姓名</label>

        <div class="col-sm-8">
            <input class="form-control" name="customerName" value="${ykOrderParams.customerName!''}" placeholder=""
                   type="text">
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">引荐人</label>

        <div class="col-sm-8">
            <input class="form-control" name="yjName" value="${ykOrderParams.yjName!''}" placeholder="" type="text">
        </div>
    </div>
</div>

<#--   <div class="row">
       <div class="form-group col-md-4">
           <label class="col-sm-4 control-label" for="exampleInputEmail2">电话</label>
           <div class="col-sm-8">
               <input class="form-control" name="phone" value="${ykOrderParams.phone!''}" placeholder="" type="text">
           </div>
       </div>
      &lt;#&ndash; <div class="form-group col-md-4">
           <label class="col-sm-4 control-label" for="exampleInputEmail2">年龄</label>
           <div class="col-sm-8">
               <input class="form-control" name="age" value="${ykOrderParams.age!''}" placeholder="" type="text">
           </div>
       </div>
       <div class="form-group col-md-4">
           <label class="col-sm-4 control-label" for="exampleInputEmail2">性别</label>
           <div class="col-sm-8">
               <input class="form-control" name="sex" value="${ykOrderParams.sex!''}" placeholder="" type="text">
           </div>
       </div>&ndash;&gt;
   </div>-->
<div class="row">
<#--<div class="form-group col-md-4">
    <label class="col-sm-4 control-label" for="exampleInputEmail2">地址</label>
    <div class="col-sm-8">
        <input class="form-control" name="address" value="${ykOrderParams.address!''}" placeholder="" type="text">
    </div>
</div>
<div class="form-group col-md-4">
    <label class="col-sm-4 control-label" for="exampleInputEmail2">产品id</label>
    <div class="col-sm-8">
        <input class="form-control" name="vipId" value="${ykOrderParams.vipId!''}" placeholder="" type="text">
    </div>
</div>-->
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">会员类型</label>

        <div class="col-sm-8">
        <@select name="vipType"  value="${ykOrderParams.vipType!''}" list=vipTypeList class="form-control"/>
                                        <#--<input class="form-control" name="vipType" value="${ykOrderParams.vipType!''}" placeholder="" type="text">-->
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">产品名称</label>

        <div class="col-sm-8">
            <input class="form-control" name="productName" value="${ykOrderParams.productName!''}" placeholder=""
                   type="text">
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">渠道类型</label>

        <div class="col-sm-8">
        <@select name="channelType" value="${ykOrderParams.channelType!''}" list=channelTypeList class="form-control"/>
                                            <#--<input class="form-control" name="channelType" value="${ykOrderParams.channelType!''}" placeholder="" type="text">-->
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">分管人</label>

        <div class="col-sm-8">
            <input class="form-control" name="fgName" value="${ykOrderParams.fgName!''}" placeholder="" type="text">
        </div>
    </div>
</div>
<div class="row">

<#-- <div class="form-group col-md-3">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">金额</label>
                                    <div class="col-sm-8">
                                        <input class="form-control" name="money" value="${ykOrderParams.money!''}" placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">周期</label>
                                    <div class="col-sm-8">
                                        <input class="form-control" name="vipCycle" value="${ykOrderParams.vipCycle!''}" placeholder="" type="text">
                                    </div>
                                </div>-->
</div>
<#--  <div class="row">
      <div class="form-group col-md-4">
          <label class="col-sm-4 control-label" for="exampleInputEmail2">成本类型</label>
          <div class="col-sm-8">
              <input class="form-control" name="costType" value="${ykOrderParams.costType!''}" placeholder="" type="text">
          </div>
      </div>
      <div class="form-group col-md-4">
          <label class="col-sm-4 control-label" for="exampleInputEmail2">成本金额或比例</label>
          <div class="col-sm-8">
              <input class="form-control" name="costMoney" value="${ykOrderParams.costMoney!''}" placeholder="" type="text">
          </div>
      </div>
      <div class="form-group col-md-4">
          <label class="col-sm-4 control-label" for="exampleInputEmail2">上门次数</label>
          <div class="col-sm-8">
              <input class="form-control" name="doorNum" value="${ykOrderParams.doorNum!''}" placeholder="" type="text">
          </div>
      </div>
  </div>-->
<div class="row">
<#--<div class="form-group col-md-4">
    <label class="col-sm-4 control-label" for="exampleInputEmail2">上门金额</label>
    <div class="col-sm-8">
        <input class="form-control" name="doorMoney" value="${ykOrderParams.doorMoney!''}" placeholder="" type="text">
    </div>
</div>-->

    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">下单日期</label>

        <div class="col-sm-8">
            <input class="form-control" name="billTime" value="${ykOrderParams.billTime!''}" placeholder="" type="text">
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2"> — — — </label>

        <div class="col-sm-8">
            <input class="form-control" name="billFinish" value="${ykOrderParams.billFinish!''}" placeholder=""
                   type="text">
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">开卡日期</label>

        <div class="col-sm-8">
            <input class="form-control" name="billStart" value="${ykOrderParams.billStart!''}" placeholder=""
                   type="text">
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2"> — — — </label>

        <div class="col-sm-8">
            <input class="form-control" name="finishStart" value="${ykOrderParams.finishStart!''}" placeholder=""
                   type="text">
        </div>
    </div>
</div>
<div class="row">

    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">到期日期</label>

        <div class="col-sm-8">
            <input class="form-control" name="billEnd" value="${ykOrderParams.billEnd!''}" placeholder="" type="text">
        </div>
    </div>


    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2"> — — — </label>

        <div class="col-sm-8">
            <input class="form-control" name="finishEnd" value="${ykOrderParams.finishEnd!''}" placeholder=""
                   type="text">
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">促会人</label>

        <div class="col-sm-8">
            <input class="form-control" name="chName" value="${ykOrderParams.chName!''}" placeholder="" type="text">
        </div>
    </div>

    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">是否退会</label>

        <div class="col-sm-8">
        <@select name="vipBack" value="${ykOrderParams.vipBack!''}" list=vipBackTypeList class="form-control"/>
                                        <#--<input class="form-control" name="vipBack" value="${ykOrderParams.vipBack!''}" placeholder="" type="text">-->
        </div>
    </div>
</div>
<div class="row">
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">渠道来源</label>

        <div class="col-sm-8">
        <@select name="spareC" value="${ykOrderParams.spareC!''}" list=vipqdTypeList class="form-control"/>
                                        <#--<input class="form-control" name="vipBack" value="${ykOrderParams.vipBack!''}" placeholder="" type="text">-->
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">是否包含代理</label>

        <div class="col-sm-8">
        <@select name="spareG" value="${ykOrderParams.spareG!''}" list=vipBackTypeList class="form-control"/>
                                        <#--<input class="form-control" name="vipBack" value="${ykOrderParams.vipBack!''}" placeholder="" type="text">-->
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4 control-label" for="exampleInputEmail2">显示条数:</label>

        <div class="col-sm-8">
            <input class="form-control" name="pageSize" value="${ykOrdersTable.page.pageSize}" placeholder=""
                   type="text"/>
        </div>
    </div>
    <div class="form-group col-md-3">
        <label class="col-sm-4"></label>

        <div class="col-sm-8">
            <button type="button" class="btn btn-primary" onclick="refreshTable()">查询</button>
            <button type="reset" class="btn btn-default">重置</button>
        </div>
    </div>
</div>


</form>
</div>
</div>
</section>
<section class="tile">
    <div class="tile-header">
        <h1>
        <@security.authorize ifAnyGranted="ROLE_HYGLXX_A">
            <button type="button" class="btn btn-green" onclick="popAddOrModify();"><i class="fa fa-plus"></i><span
                    class="margin-left-5">新增</span></button>
        </@security.authorize>
        <@security.authorize ifAnyGranted="ROLE_HYGLXX_D">
            <button type="button" class="btn btn-cyan" onclick="deleteYkOrder();"><i class="fa fa-trash-o"></i><span
                    class="margin-left-5">删除</span></button>
        </@security.authorize>
        <@security.authorize ifAnyGranted="ROLE_HYGLXX_DR">
            <button id="importCustBtn" type="button" class="btn btn-cyan"><i
                    class="fa fa-arrow-circle-o-down"></i><span class="margin-left-5">导入模板</span>
            </button>
        </@security.authorize>
        <@security.authorize ifAnyGranted="ROLE_HYGLXX_DRCZ">
            <button type="button" class="btn  btn-primary" onclick="doDownLoadTemplate();"><i
                    class="fa fa-download"></i><span class="margin-left-5">导入模板下载</span></button>
        </@security.authorize>
            <button type="button" class="btn btn-green" onclick="popExportExcel();"><i
                    class="fa fa-plus"></i><span class="margin-left-5">导出</span></button>
        </h1>
    </div>
    <div class="tile-body nopadding">
        <div class="table-responsive" id="tableContent">
        <#include "table.ftl"/>
        </div>
    </div>
</section>
</div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
</div>
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
</div>
<form id="Form_Download" action="${absoluteContextPath}/yk/ykOrder/downloadTemplate" method="post"
      style="display: none">
    <input name="serverFileName" type="hidden" value="VipDownload.xlsx"/>
    <!-- 下载潜在客户导入模板 -->
    <input name="clientFileName" type="hidden" value="会员管理导入.xlsx"/>
    <!-- 下载潜在客户导入模板 -->
</form>
<form id="custUploadForm" method="post" enctype="multipart/form-data"
      action="${absoluteContextPath}/upload/ajax" style="display: none">
    <input type="file" name="file"/>
    <input type="text" name="fileType" value="xlsx">
</form>
<div class="modal fade" id="errorMessage" tabindex="-1" role="dialog" aria-labelledby="cardCode04"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">导入提示</h4>
            </div>
            <div class="modal-body">
                <div id="info"></div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
</div>


</body>
</html>
